{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/qsh-bert-prompt/lib/python3.7/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading and preparing dataset text/default to /root/.cache/huggingface/datasets/text/default-d5b6325f0a01987b/0.0.0/cb1e9bd71a82ad27976be3b12b407850fe2837d80c22c5e03a28949843a8ace2...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Downloading data files: 100%|██████████| 2/2 [00:00<00:00, 9238.56it/s]\n",
      "Extracting data files: 100%|██████████| 2/2 [00:00<00:00, 293.12it/s]\n",
      "                                                        \r"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset text downloaded and prepared to /root/.cache/huggingface/datasets/text/default-d5b6325f0a01987b/0.0.0/cb1e9bd71a82ad27976be3b12b407850fe2837d80c22c5e03a28949843a8ace2. Subsequent calls will reuse this data.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [00:00<00:00, 1156.41it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'text': '电脑\\t(1)这款笔记本外观感觉挺漂亮的，分量吗，对我来说不算沉。 (2)安装了WindowsXP系统后，运行的速度挺快。发热量没有想象中那么大。可能尚未运行很耗资源的程序，没有感到内存的弊病。不过，1G的内存确实有点小。 (3)附赠的包很不错，挺有手感的。但是附赠的鼠标实在是太小了，幸好同时订了一个双飞燕的鼠标哟。'}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "from datasets import load_dataset\n",
    "\n",
    "train_path = \"data/comment_classify/train.txt\"\n",
    "dev_path = \"data/comment_classify/dev.txt\"\n",
    "dataset = load_dataset('text', data_files={'train': train_path, 'dev': dev_path})\n",
    "\n",
    "for i in dataset['train']:\n",
    "    print(i)\n",
    "    break\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import os\n",
    "\n",
    "import mindspore\n",
    "from mindspore import ops\n",
    "from mindnlp.models import BertModel, BertConfig\n",
    "import numpy as np\n",
    "\n",
    "def from_dict(json_object):\n",
    "    \"\"\"Constructs a `BertConfig` from a Python dictionary of parameters.\"\"\"\n",
    "    config = BertConfig()\n",
    "    for key, value in json_object.items():\n",
    "        config.__dict__[key] = value\n",
    "    return config\n",
    "\n",
    "def from_json_file(json_file):\n",
    "    \"\"\"Constructs a `BertConfig` from a json file of parameters.\"\"\"\n",
    "    with open(json_file, \"r\", encoding='utf-8') as reader:\n",
    "        text = reader.read()\n",
    "    return from_dict(json.loads(text))\n",
    "\n",
    "model_folder_path = \"ckpt\"\n",
    "config_path = os.path.join(model_folder_path, 'config.json')\n",
    "config = from_json_file(config_path)\n",
    "bert = BertModel(config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[WARNING] ME(3426995:140559114666112,MainProcess):2023-04-05-10:57:01.501.853 [mindspore/ops/operations/array_ops.py:1606] WARN_DEPRECATED: Zeros will be deprecated in the future. Please use class `mindspore.ops.zeros`.\n",
      "/opt/conda/envs/qsh-bert-prompt/lib/python3.7/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from utils import save_jsonfile\n",
    "from mindnlp.models import BertConfig\n",
    "config = BertConfig(100)\n",
    "save_jsonfile(config, \"config.json\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "qsh-bert-prompt",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
